<?php
/**
 * Author: bedirhan
 */

    if(isset($_POST['input']) && isset($_POST['pattern'])){
        $input = $_POST['input'];
        $pattern = $_POST['pattern'];
        if(preg_match($pattern, $input, $matches)){
            $result = "MATCH";
        }
        else
            $result = "NO MATCH";
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>PHP Regex Tester</title>
        <script>
            window.onload = function(){
              var input = document.getElementById("input");
              var pattern = document.getElementById("pattern");
              //input.value = "<?php echo str_replace("\"", "\\\"", $input); ?>";
              //pattern.value = "<?php echo str_replace("\"", "\\\"", $pattern); ?>";              
            }
        </script>
    </head>
    <body>
        <form action="RegexTester.php" method="POST">
            <table>
            <tr>
            <td>
                Input:
            </td>
            <td>
              <input type="text" id="input" name="input" size=80 />
            </td>
            </tr>
            <tr>
            <td>
                Pattern:
            </td>
            <td>
              <input type="text" id="pattern" name="pattern" size=80/>
            </td>
            </tr>
            </table>
          
          <input type="submit" value="TEST"/>
        </form>
        <h3><?php echo $result; ?></h3>
        <div>
          <?php
            if(strcmp($result, "MATCH") == 0){
                foreach($matches as $match)
                  echo htmlentities($match, ENT_QUOTES, 'UTF-8') . '<br/>';
            }
            echo 'Input:#' . htmlentities($input, ENT_QUOTES, 'UTF-8') . '#<br/>';
            echo 'Pattern:#' . htmlentities($pattern, ENT_QUOTES, 'UTF-8') . '#<br/>';
          ?>
          
        </div>
    </body>
</html>
